import { ReqPage, ResPage } from '@/api/interface'
import { TBY } from '@/api/config/servicePort'
import http from '@/api'

export namespace MonitoringStation {
  /**查询参数 */
  export interface Query extends ReqPage {
    deviceName?: string
    deviceCode?: string
    position?: string
  }

  /**列表内容 */
  export interface Record {
    id: number
    deviceName: string
    deviceCode: string
    deviceType: string
    deviceModel: string
    longitude: string
    latitude: string
    paramsCount: number
    headName: string
    buildDate: string
    buildDateFormat: string
  }

  /**详情 */
  export interface Form {
    id: number
    deviceName: string
    deviceCode: string
    deviceType: string
    deviceModel: string
    longitude: string
    latitude: string
    paramsCount: number
    headName: string
    buildDate: string
    buildDateFormat: string
  }
}

export const pageMonitoringStation = (params: MonitoringStation.Query) => {
  return http.get<ResPage<MonitoringStation.Record>>(TBY + `/monitoring_station/page`, params)
}

// 山峰详情
export const getMonitoringStationDetail = (id: number) => {
  return http.get<Partial<MonitoringStation.Form>>(TBY + `/monitoring_station/get`, { id }, { loading: false })
}

// 新增或修改山峰
export const saveOrUpdateMonitoringStation = (params: Partial<MonitoringStation.Form>) => {
  return http.post(TBY + `/monitoring_station/save`, params)
}

// 删除山峰
export const removeMonitoringStation = (id: number) => {
  return http.delete(TBY + `/monitoring_station/delete`, { id })
}

// 验证编码是否存在
export const codeExist = (deviceCode: string, id?: number) => {
  return http.get<boolean>(TBY + '/monitoring_station/exist', { deviceCode, id }, { loading: false })
}
